<?php
require_once("./DButil.php");

$courseId=$_REQUEST["id"];
$courseName=$_REQUEST["name"];
$status=$_REQUEST["status"];


$sql="select * from t_course where courseName='{$courseName}'";
if (query($sql)) {
    $result = [
        "msg" => "添加失败,课程名称重复",
        "code" => 404,
        "success" => false
    ];
}else{
    $sql1="insert into t_course (courseId,courseName,status) values ('{$courseId}','{$courseName}',{$status})";
    $add=update($sql1);
    if ($add) {
        $result = [
            "msg" => "添加成功",
            "code" => 200,
            "success" => true
        ];
    }else{
        $result = [
            "msg" => "添加失败",
            "code" => 400,
            "success" => false
        ];
    }
}

header("Content-Type:application/json;charset=utf-8");
echo json_encode($result);

?>